﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SharePointClientHelper
{
    public partial class GetUsersInGroup : Form
    {
        public GetUsersInGroup()
        {
            InitializeComponent();
            SPClientHelper spcHelper = SPClientHelper.GetSPClientHelper();
            List<MyGroup> lstMyGroups = spcHelper.GetSiteGroups();

            ddlGroup.DataSource = lstMyGroups;
            ddlGroup.DisplayMember = "Title";
            ddlGroup.ValueMember = "ID";
        }

        private void btnGetUsers_Click(object sender, EventArgs e)
        {
            if (ddlGroup.SelectedIndex > -1)
            {
                SPClientHelper spcHelper = SPClientHelper.GetSPClientHelper();
                MyGroup group = (MyGroup)ddlGroup.SelectedItem;
                List<MyUser> listUsers = spcHelper.GetAllUsersInGroup(group.Title);
                dgvUsers.DataSource = listUsers;

                lblCount.Visible = true;
                lblCount.Text = listUsers.Count().ToString();
                lblCountText.Visible = true;

                
            }

        }
    }
}
